# -*- coding: utf-8 -*-
# @Author  : gaoyu
# @Time    : 2025/6/17 15:12
# @Function:
from datetime import datetime, timedelta


def add_8_hours_to_dt_fields(data):
    """
    为数据结构中的dt字段统一加8小时
    """
    if isinstance(data, dict):
        # 处理字典中的dt字段
        if 'dt' in data and isinstance(data['dt'], str):
            try:
                dt_obj = datetime.strptime(data['dt'], "%Y-%m-%d %H:%M:%S")
                dt_obj_plus8 = dt_obj + timedelta(hours=8)
                data['dt'] = dt_obj_plus8.strftime("%Y-%m-%d %H:%M:%S")
            except ValueError:
                pass  # 如果时间格式不匹配，跳过

        # 递归处理字典中的其他值
        for key, value in data.items():
            if isinstance(value, (dict, list)):
                add_8_hours_to_dt_fields(value)

    elif isinstance(data, list):
        # 递归处理列表中的每个元素
        for item in data:
            add_8_hours_to_dt_fields(item)

    return data
